Java Development for Mobile Phones

Part 1

 

Exploring the Java Platform Micro Edition (Java ME)

 

Sun offers an introduction to Java ME at http://java.sun.com/javame/technology/index.jsp

 

The elements of Java Me are Configurations and Profiles.

 

The most commonly supported configuration for mobile phones is CLDC. You can find information about CLDC at http://java.sun.com/products/cldc/overview.html 

 

The most commonly supported profile for mobile phones is MIDP. You can find information about MIDP at http://java.sun.com/products/midp/overview.html

 

In addition to the above there are also a number of optional APIs.

 

Task 1

 

Pick a mobile phone that supports Java. The phone you select may be the one you own or a randomly selected one. Find out which version of CLDC and MIDP it supports. Find out whether it supports any optional APIs and what their purpose is.

 

Phone Manufacturer SDKs

 

Most manufacturers of Java-enabled mobile phones provide their own SDK. These SDKs in addition to the basic CLDC and MIDP also support any optional APIs that are supported by the target device class. Moreover these SDKs usually include emulators of the particular target devices.

 

You must be careful in that if your programs utilise features that are beyond the basic CLDC/MIDP then they may not run on devices that do not support these features. So, if you want your applications to be portable you should limit yourselves to the widely supported APIs.

 

Note that some manufacturers provide more than one SDK targeting different sets of their products.

 

Task 2

 

Find out whether there is a manufacturer SDK for the device you chose for the first exercise.

 

If you plan to do development on your selected mobile device, then it is probably a good idea to download and install the manufacturer SDK. This would allow you to test your applications in the same look and feel as the real device you are targeting.

 

Note that devices have a certain amount of freedom in the way they manage the look and feel of Java ME applications. As a result, the same application may look different when run on different devices and different emulators.

 

Java ME development using common IDEs

 

Freely available IDEs like Eclipse and NetBeans provide support for Java ME application development. In order to do for Eclipse you must have the EclipseME plugin, while for NetBeans you must have the Mobility pack.

 

Newer versions of NetBeans can be downloaded and installed to include the Mobility pack making them ready for Java ME development. For this reason I recommend that use NetBeans for your development.

 

Task 3

 

For the IDE of your choice ensure that it provides the right support for Java ME development. This may involve downloading and installing the approach pack or plugin.

 

If you are targeting your development to a particular device and you have found a manufacturer’s SDK, you must configure your IDE to use the SDK. This would allow you to automatically invoke the manufacturer’s emulator when running your application and would create the correct files that you need to run the application on your phone.

 

Introduction to Java ME application development

 

A Java ME application is referred to as a MIDlet. A collection of one or more MIDlets is packages into a Java Archive (JAR) file. It is also called a MIDlet Suite. It contains all classes needed by the suite, MIDlet information like name, main class, icon, vendor, etc, and non-class resources like images, sound files or even XML files. The MIDlet Suite is described by a Java Application Descriptor (JAD) file.

 

The JAR file is used to install and uninstall applications on a device. The device application manager using specific callback methods of the MIDlet class to communicate with the application.

 

When building a MIDlet the source files and descriptor file are the only ones that have to be provided by the developer. Note that IDEs will usually generate a basic descriptor file for the application you are building.

 

The build process starts with the compilation of the source files, then the bytecode files are packaged into a JAR file and the accompanying JAD file needs to be provided, then the byte code is pre-verified, finally the JAD file and the pre-verified JAR file are deployed to the device.

 

The MIDlet lifecycle includes a number of different states: start, paused, active and destroyed. Transitions between states are triggered from the MIDlet itself or externally by the application manager.

 

When constructed a MIDlet enters the paused state. Then, the application manager calls the MIDlet startApp() method shifting it to the active state. When the application manager calls the pauseApp() method the MIDlet shifts to the paused state. The MIDlet shifts to the active state when the application manager calls the startApp() method again. The MIDlet terminates when the application manager calls the destroyApp() method. The call can be unconditional, which means that the MIDlet has no option but to free all resources and shutdown or the MIDlet may request to keep running by it is up to the request manager to decide whether to accept the request.

 

All the methods called by the application manager are callback methods and are not supposed to be called directly by the MIDlet developer.

 

Note that this material is based on the Java ME Nokia Platforms E-Learning available online at www.forum.nokia.com

 

You can also find a good introduction on Java ME development in the material provided by the Center for Mobile Education and Research, University of Guelph.

 

Task 4

 

Develop a HelloWorld MIDlet and run on your target emulator and if applicable to your target device.

 

NetBeans steps:

1.      Start by creating an appropriately named new Java ME project – Mobile Application. Select the appropriate platform and default configuration

2.      In the Flow pane you should have the MIDlet for your application and a form. Add a stringItem to the form and configure its label and text properties to “Hi there” and “Anyone out there” respectively. Try to remove the “Hello, World!” default stringItem.

3.      Run your project.

 

If your program ran fine, then examine its Source to try and understand the code that created it.

 

Task 5

 

Elaborate on your application you build in the Task 4 by adding the functionality to create a personalised message. In this case when the application starts the user is presented with a screen (a form) with a text field to enter their name (a string of certain length). The screen has also two commands, exit that exits the application, and submit, that moves on to the screen you created above showing now the message Hi there <name entered>. The screen would have two commands, exit and back. The latter gets you back to the first screen.